<template>
  <div>
    <el-descriptions title="分路信息" direction="horizontal" :column="2">
      <el-descriptions-item label="设备ID">{{detail.deviceid}}</el-descriptions-item>
      <el-descriptions-item label="分路ID">{{detail.lnid}}</el-descriptions-item>
      <el-descriptions-item label="电压A">{{status.voltage?status.voltage[0]:''}}V</el-descriptions-item>
      <el-descriptions-item label="电压B" v-if="status.voltage && typeof status.voltage[1] != 'undefined' ">{{status.voltage[1]}}</el-descriptions-item>
      <el-descriptions-item label="电压C" v-if="status.voltage && typeof status.voltage[2] != 'undefined' ">{{status.voltage[2]}}</el-descriptions-item>
      <el-descriptions-item label="电流A">{{status.current?status.current[0]/1000:''}}A</el-descriptions-item>
      <el-descriptions-item label="电流B" v-if="status.current && typeof status.current[1] != 'undefined'">{{status.current[1]/1000}}A</el-descriptions-item>
      <el-descriptions-item label="电流C" v-if="status.current && typeof status.current[2] != 'undefined'">{{status.current[2]/1000}}A</el-descriptions-item>
      <el-descriptions-item label="有功功率A">{{status.power?status.power[0]:''}}W</el-descriptions-item>
      <el-descriptions-item label="有功功率B" v-if="status.power && typeof status.power[1] != 'undefined'">{{status.power[1]}}W</el-descriptions-item>
      <el-descriptions-item label="有功功率C" v-if="status.power && typeof status.power[2] != 'undefined'">{{status.power[2]}}W</el-descriptions-item>
      <el-descriptions-item label="无功功率">{{status.nopower}}W</el-descriptions-item>
      <el-descriptions-item label="漏电电流">{{status.leakage}}A</el-descriptions-item>
      <el-descriptions-item label="频率">{{status.frequency}}Hz</el-descriptions-item>
      <el-descriptions-item label="电能">{{status.electricity}}Kwh</el-descriptions-item>
      <el-descriptions-item label="温度">{{status.temp}}℃</el-descriptions-item>
      <el-descriptions-item label="短路跳闸次数">{{status.shortcircuitnum}}次</el-descriptions-item>
      <el-descriptions-item label="硬件版本号">{{status.version}}</el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
import { getsubset } from '@/api/equipment/subdevice.js';
import { opertioncmd02 } from '@/api/ws/cmdoper.js';
import { mapGetters } from 'vuex';

export default {
  props: ['data','visible'],
  watch: {
    data: {
      handler: function (val) {
        if (val) {
          console.log(val);
          this.query.deviceid = val.deviceid;
          this.query.lnid = val.lnid;         
          //opertioncmd02(val.deviceid, val.lnid, 'getsomeswitch', 'CMD-2', 1);
          this.getData();
        }
      },
      immediate: true,
    },
    deviceswitchinfo: {
      handler: function (val) {
        if (val.desired) {
          let status = {};
          val.desired.arrays.forEach((item) => {
            console.log(item.device.id, this.query.lnid);
            if (item.device.id == this.query.lnid) {
              console.log('==============');
              status = item.status;
            }
            this.status = status
          });
        }
        console.log(val, '开关信息');
      },
      immediate: true,
    },
    visible: {
      handler: function (val) {
        if (!val) {
          clearInterval(this.cmdhandler);
          this.status = {}
        }else{
          //关闭窗口的时候 关闭数据请求
          opertioncmd02(this.query.deviceid, this.query.lnid, 'getsomeswitch', 'CMD-2', 1);
          this.cmdhandler = setInterval(()=> {
            opertioncmd02(this.query.deviceid, this.query.lnid, 'getsomeswitch', 'CMD-2', 1);
          }, 5000);
        }
      },
      immediate: true,
    },
  },
  computed: {
    ...mapGetters(['deviceswitchinfo']),
  },
  data() {
    return {
      query: {},
      formData: {
        elecmax: '',
      },
      detail: {},
      deviceArr: {},
      subsetDetail: {},
      status:{},//开关信息

      cmdhandler:null,
    };
  },
  methods: {
    getData() {
      getsubset(this.query).then((res) => {
        this.detail = res.data.detail;
        this.deviceArr = res.data.deviceArr;
        this.subsetDetail = res.data.subsetDetail;
      });
    },
  },
};
</script>

<style scoped></style>
